package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.ChuangyeMapper;
import work.xiaohong.gupiao.pojo.Chuangye;
import work.xiaohong.gupiao.service.ChuangyeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChuangyeServiceImpl implements ChuangyeService {

    @Autowired
    private ChuangyeMapper chuangyeMapper;


    /**
     * 条件+分页查询Chuangye
     * @param chuangye 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Chuangye> findPage(Chuangye chuangye, int page, int size){
        // 构建查询条件
        QueryWrapper<Chuangye> queryWrapper = new QueryWrapper<Chuangye>(chuangye);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chuangyeMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Chuangye
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Chuangye> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chuangyeMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Chuangye
     * @param chuangye
     * @return
     */
    @Override
    public List<Chuangye> findList(Chuangye chuangye){
        // 构建查询条件
        QueryWrapper<Chuangye> queryWrapper = new QueryWrapper<Chuangye>(chuangye);
        // 查询数据
        return chuangyeMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Chuangye
     * @param id
     */
    @Override
    public void delete(Integer id){
        chuangyeMapper.deleteById(id);
    }

    /**
     * 根据ID修改Chuangye
     * @param chuangye
     */
    @Override
    public void update(Chuangye chuangye){
        chuangyeMapper.updateById(chuangye);
    }

    /**
     * 增加Chuangye
     * @param chuangye
     */
    @Override
    public void add(Chuangye chuangye){
        chuangyeMapper.insert(chuangye);
    }

    /**
     * 根据ID查询Chuangye
     * @param id
     * @return
     */
    @Override
    public Chuangye findById(Integer id){
        return  chuangyeMapper.selectById(id);
    }

    /**
     * 查询全部Chuangye数据
     * @return
     */
    @Override
    public List<Chuangye> findAll() {
        return chuangyeMapper.selectList(null);
    }
}
